var currentIndex;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 1,
    classfilyDataListProgram: [],
    findmask: true
  },

  showmask: function (event) {
    var index = event.currentTarget.dataset.index;
    currentIndex = index;
    var vm = this
    wx.navigateTo({
      url: '/pages/find_same/find_same?categoryId=' + vm.data.classfilyDataListProgram[currentIndex].categoryId,
    })
  },

  /**
   * 跳转到播放详情页面
   */
  todetails: function(e) {
    var season = e.currentTarget.dataset.season;
    var id = e.currentTarget.dataset.id;
    var title = e.currentTarget.dataset.title; //节目标题 

    var flag = e.currentTarget.dataset.flag
    if (flag != "0") {
      wx.showToast({
        title: '该栏目已下架',
      })
      return
    }
    var vm = this
    //热听绑定、有声小说等、、、点击埋点 
    vm.setData({
      userIdss: wx.getStorageSync("userId"), //用户编号
      homeClassifyProgramId: id, //热听榜等。。栏目点击Id记录
      homeClassifyProgramName: title, //热听榜。。等栏目点击Name记录
    })
    wx.navigateTo({
      url: "/pages/day_day_listen/details/details?id=" + id + "&season=" + season,
      success: function() {},
      fail: function() {}
    })
  },
  getdata: function(status) {
    var vm = this
    var data = {
      "startPoint": vm.data.page,
      "maxPage": "10",
      "type": "2",
      "userId": wx.getStorageSync("userId"),
      "platform": 0
    }
    getApp().requestLoading(getApp().globalData.https + "orderResource/myBuyRecord",
      "get", data, "加载中..",
      function(res) {
        console.log(res);
        wx.setStorageSync("buyedtime", new Date().getTime())
        wx.stopPullDownRefresh()
        if (res.code == 0) {
          vm.setData({
            classfilyDataListProgram: vm.data.classfilyDataListProgram.concat(res.data.data),
            totalPages: res.data.totalPages,
            maxpagesize: Math.floor(res.data.totalResults / vm.data.pagesize) + ((res.data.totalResults % vm.data.pagesize) == 0 ? 0 : 1),
            showloading: false
          })
        } else {
          vm.setData({
            classfilyDataListProgram: [],
            bottomtext: '还没有历史记录哦.',
            showloading: false,
          })
        }

      },
      function(res) {
        console.log(res)
      });
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    var vm = this
    if (vm.data.page >= vm.data.totalPages) {
      vm.setData({
        showbottom: true,
        bottomtext: '没有更多内容了'
      })
      return
    }
    this.setData({
      page: vm.data.page + 1
    })
    vm.getdata(0)
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.getdata(0)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})